﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;

namespace ArithmeticExpressionCalculator
{
    class ArithmeticExpressionIsValid : IIsValid
    {
        public bool IsAllSymbolsCorrect(string str)
        {
            for (int i = 0; i < str.Length; i++)
            {
                if (!(Char.IsDigit(str, i) || str[i] == ',' || Char.IsWhiteSpace(str, i) ||
                    str[i] == '+' || str[i] == '-' || str[i] == '*' || str[i] == '/' || str[i] == '(' || str[i] == ')'))
                    return false;
            }
            return true;
        }
        public bool ParenthesisBrakets(string str)
        {
            int count = 0;
            for (int i = 0; i < str.Length; i++)
            {
                if (str[i] == '(') count++;
                else if (str[i] == ')') count--;
                if (count < 0) return false;
            }
            return count == 0;
        }
        public bool IsValid(string str)
        {
            return IsAllSymbolsCorrect(str) && ParenthesisBrakets(str);
        }
    }
}
